/*=========================================================================

Program:   Medical Imaging & Interaction Toolkit
Language:  C++
Date:      $Date: 2010-09-27 02:40:25 +0800 (星期一, 2010-09-27) $
Version:   $Revision: 26363 $

Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.

=========================================================================*/


#ifndef WxTexturedSurfaceVtkMapper3D_H_HEADER_INCLUDED_C1907273
#define WxTexturedSurfaceVtkMapper3D_H_HEADER_INCLUDED_C1907273

#include <mitkCommon.h>
#include <mitkVtkMapper3D.h>
#include <mitkSurface.h>
#include <mitkBaseRenderer.h>

#include <vtkActor.h>
#include <vtkOpenGLPolyDataMapper.h>
#include <vtkPainterPolyDataMapper.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolyDataNormals.h>
#include <vtkPlaneCollection.h>
#include <vtkLookupTable.h>
#include <vtkTexture.h>
#include <vtkImageData.h>

#include "WxExtentionExports.h"

namespace mitk {


//##Documentation
//## @brief Vtk-based mapper for Surface use texture
//##
//## @ingroup Mapper



class WxExtention_EXPORT WxTexturedSurfaceVtkMapper3D : public VtkMapper3D
{
public:

  mitkClassMacro(WxTexturedSurfaceVtkMapper3D, VtkMapper3D);

  itkNewMacro(Self);

  itkSetMacro(GenerateNormals, bool);

  itkGetMacro(GenerateNormals, bool);

  //enable ImmediateModeRendering for vtkMapping
  //yet to solve bug 1398
  void SetImmediateModeRenderingOn(int on = 1);

  itkGetMacro(ImmediateModeRenderingOn, int);

  virtual const mitk::Surface* GetInput();

  virtual vtkProp *GetVtkProp(mitk::BaseRenderer *renderer);

  virtual void ApplyProperties(vtkActor* actor, mitk::BaseRenderer* renderer);

  static void SetDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer = NULL, bool overwrite = false);

protected:
  WxTexturedSurfaceVtkMapper3D();

  virtual ~WxTexturedSurfaceVtkMapper3D();

  virtual void GenerateData(mitk::BaseRenderer* renderer);

  virtual void ResetMapper( mitk::BaseRenderer* renderer );

  /** Checks whether the specified property is a ClippingProperty and if yes,
   * adds it to m_ClippingPlaneCollection (internal method). */
  virtual void CheckForClippingProperty( mitk::BaseRenderer* renderer, mitk::BaseProperty *property );

  bool m_GenerateNormals;
  vtkLookupTable* m_DefaultLookupTable;

  //enable ImmediateModeRendering for the vtkMapper
  int m_ImmediateModeRenderingOn;

public:
    
  class LocalStorage : public mitk::Mapper::BaseLocalStorage
  {
    public:

      vtkActor* m_Actor;
      vtkPolyDataMapper *m_VtkPolyDataMapper;
      vtkPolyDataNormals *m_VtkPolyDataNormals;
      vtkPlaneCollection *m_ClippingPlaneCollection;
      vtkTexture* m_Texture;

      itk::TimeStamp m_ShaderTimestampUpdate;

      LocalStorage()
      {
        m_VtkPolyDataMapper = vtkOpenGLPolyDataMapper::New();
        m_VtkPolyDataNormals = vtkPolyDataNormals::New();
        m_Actor = vtkActor::New();
        m_ClippingPlaneCollection = vtkPlaneCollection::New();
        m_Texture=vtkTexture::New();
        m_Actor->SetTexture(m_Texture);
        m_Actor->SetMapper(m_VtkPolyDataMapper);
      }

      ~LocalStorage()
      {
        m_VtkPolyDataMapper->Delete();
        m_VtkPolyDataNormals->Delete();
        m_Actor->Delete();
        m_ClippingPlaneCollection->Delete();
        m_Texture->Delete();
      }
  };
    
  mitk::Mapper::LocalStorageHandler<LocalStorage> m_LSH;

  static void ApplyMitkPropertiesToVtkProperty(mitk::DataNode *node, vtkProperty* property, mitk::BaseRenderer* renderer);
  static void SetDefaultPropertiesForVtkProperty(mitk::DataNode* node, mitk::BaseRenderer* renderer, bool overwrite);

};

} // namespace mitk

#endif /* WxTexturedSurfaceVtkMapper3D_H_HEADER_INCLUDED_C1907273 */
